package com.study.mr.writablecomparable;

import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableComparator;

/**
 * 自定义比较器对象，继承hadoop提供的比较器对象WritableCompartor
 */
public class FlowBeanComparable extends WritableComparator{
    //指定当前比较器对象为谁服务
    public FlowBeanComparable() {
        super(FlowBean.class,true);
    }

    /**
     * 自定义比较器对象，升序排列总流量
     * @param a
     * @param b
     * @return
     */
    @Override
    public int compare(WritableComparable a, WritableComparable b) {
        FlowBean abean = (FlowBean) a;
        FlowBean bbean = (FlowBean) b;
        return abean.getSumFlow().compareTo(bbean.getSumFlow());
    }
}
